<template>
  <a-modal
    title="成本部门设置"
    :visible="visible"
    :width="600"
    :body-style="{ padding: '0px' }"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <div class="info" v-if="type">成本部门不参与成本分摊，在设置分摊规则（按人均分摊）时无法选到成本部门。</div>
    <div class="con">
      {{
        type
          ? '是否确认将' + value + '设置为成本部门？'
          : '取消成本部门设置后该部门不能进行成本分摊，确定取消' + value + '的成本部门设置吗？'
      }}
    </div>
  </a-modal>
</template>

<script>
import { editDepartType } from '@/api/authorityManagement'
export default {
  name: 'SettingCost',
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    type: {
      //true设置 false取消
      type: Boolean,
      default: false,
    },
    value: {
      type: String,
      default: '',
    },
    id: {
      type: [String, Number],
      default: null,
    },
  },
  data() {
    return {}
  },
  methods: {
    async handleOk() {
      try {
        const res = await editDepartType({ id: this.id, departType: this.type ? 1 : 0 })
        if (res.code === 200) {
          this.$notification.success({ message: '系统提示', description: res.message })
          this.$emit('update:visible', false)
          this.$emit('confirm')
        } else {
          this.$notification.error({ message: '系统提示', description: res.message })
        }
      } catch (e) {
        console.log(e)
      }
    },
    handleCancel() {
      this.$emit('update:visible', false)
    },
  },
}
</script>

<style lang="less" scoped>
.info {
  background-color: #feeda6;
  padding-left: 20px;
  line-height: 40px;
}
.con {
  padding: 40px 20px;
}
</style>